# Title     : TODO
# Objective : TODO
# Created by: Administrator
# Created on: 2019/7/24

library(plyr)
library(gridExtra)
library(scales)
library(egg)
library(VennDiagram)
library(optparse)
library(tidyverse)
library(ggvenn)

createWhenNoExist <- function(f) {
  !dir.exists(f) && dir.create(f)
}

deleteAndExit <- function(pdfFileName) {
  dev.off()
  file.remove(pdfFileName)
  quit(status = 0)
}

option_list <- list(
  make_option("--i", default = "AllMet.csv", type = "character", help = "metabolite data file"),
  make_option("--g", default = "SampleInfo.csv", type = "character", help = "sample group file")
)
opt <- parse_args(OptionParser(option_list = option_list))

sampleInfo <- read.csv(opt$g, header = T, stringsAsFactors = F) %>%
  select(c("SampleID", "ClassNote"))

parent <- paste0("./")
createWhenNoExist(parent)
fileName <- paste0(parent, "/AllMet_Tests_Joined.csv")
data <- read_csv(fileName)
uniData <- data %>%
  filter(IS_Uni_Test_Pooled_Sig == 1) %>%
  .$Metabolite
uniData
mulData <- data %>%
  filter(IS_OPLSDA_Sig == 1) %>%
  .$Metabolite
mulData
pdfFileName <- paste0(parent, "/Venn_Plot.pdf")
pdf(pdfFileName, width = 8, height = 8)

data <- list(`Univariate` = uniData,
             `OPLS-DA` = mulData)
ggvenn(data = data, fill_color = c("#4040FF", "#FF4040"), stroke_size = 1.5, set_name_size = 12, show_percentage = F,
       fill_alpha = .6, text_size = 8)


dev.off()





